package itheima.zuoye.Test6;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class test {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("101","阿三面馆");
        map.put("102","阿四粥馆");
        map.put("103","阿五米馆");
        map.put("104","阿六快递");

        //用三种遍历方式遍历

        System.out.println("方式一：使用迭代器");
        Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = it.next();
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }

        System.out.println("方式二：使用增强for");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }

        System.out.println("方式三：使用Lambda表达式");
        map.entrySet().forEach(entry-> System.out.println(entry.getKey()+"---"+entry.getValue()));







    }
}
